<template>
  <div class="app-container">
    <div class="filter-container">
      <el-row>
        <el-col class="filter-column" :xl="6" :lg="8" :sm="12">
          <el-date-picker
            v-model="listQuery.date"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-col>
        <el-col class="filter-column" :xl="6" :lg="8" :sm="12">
          <el-input
            placeholder="请输入游戏名"
            v-model="listQuery.Game"
            style="width: 160px"
            clearable
            @keyup.enter.native="handleFilter"
          />
          <el-input
            placeholder="请输入游戏端口"
            v-model="listQuery.Chan"
            style="width: 160px"
            clearable
            @keyup.enter.native="handleFilter"
          />
        </el-col>
        <el-col class="filter-column" :xl="6" :lg="8" :sm="12">
          <el-input
            placeholder="请输入充值账号"
            v-model="listQuery.Account"
            style="width: 160px"
            clearable
            @keyup.enter.native="handleFilter"
          />
          <el-input
            placeholder="请输入付钱账号"
            v-model="listQuery.RechargeAccount"
            style="width: 160px"
            clearable
            @keyup.enter.native="handleFilter"
          />
        </el-col>
        <el-col class="filter-column" :xl="6" :lg="8" :sm="12">
          <el-input
            placeholder="请输入区服"
            v-model="listQuery.Server"
            style="width: 170px"
            clearable
            @keyup.enter.native="handleFilter"
          />
          <el-button type="primary" icon="el-icon-search" @click="handleFilter"
            >查询</el-button
          >
        </el-col>
      </el-row>
    </div>
    <div class="options-container">
      <el-row>
        <el-col :lg="21" :sm="20">
          <div style="width: 100%; height: 25px"></div>
        </el-col>
        <el-col :lg="3" :sm="4"
          ><div class="grid-content bg-purple">
            <el-button
              class="filter-item"
              style="margin-left: 10px"
              type="success"
              icon="el-icon-download"
              @click="downModle()"
              >导出</el-button
            >
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="table-container">
      <el-table
        v-loading="listLoading"
        :key="tableKey"
        :data="list"
        border
        fit
        @sort-change="sortHanlde"
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          prop="ID"
          sortable="custom"
          align="left"
          width="105"
        >
        </el-table-column>
        <el-table-column
          label="游戏名"
          prop="Game"
          sortable="custom"
          width="120px"
          align="left"
        >
        </el-table-column>
        <el-table-column
          label="游戏端口"
          prop="Chan"
          sortable="custom"
          width="120px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="充值人员"
          prop="Role_Name"
          sortable="custom"
          width="120px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="充值账号"
          prop="Account"
          sortable="custom"
          width="140px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="付钱账号"
          prop="RechargeAccount"
          sortable="custom"
          width="140px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="可充值金额"
          prop="Residue"
          width="160px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="金兰ID"
          prop="OtherSideID"
          sortable="custom"
          width="200px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="金兰名字"
          prop="OtherSideName"
          sortable="custom"
          width="120px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="金额"
          prop="Money"
          sortable="custom"
          width="120px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="区服"
          prop="Server"
          sortable="custom"
          width="120px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          label="充值时间"
          prop="Create_Time"
          sortable="custom"
          width="140px"
          align="left"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="pageHandle"
      />
    </div>
  </div>
</template>

<script>
import { getlist, getlist4down } from "@/api/recharge_order_stat";
import Pagination from "@/components/Pagination";
import g from "@/utils/utilFn";

export default {
  name: "rolesManage",
  components: { Pagination },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        date: [],
        start: "",
        end: "",
        Game: "",
        Chan: "",
        Account: "",
        RechargeAccount: "",
        Server: "",
        page: 1,
        limit: 10,
        filed: "ID",
        sort: "descending",
      },
      logShow: {
        show: false,
        data: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      console.log(this.listQuery);
      this.listLoading = true;
      this.listQuery.start =
        (this.listQuery.date &&
          this.listQuery.date[0] &&
          g.format(this.listQuery.date[0], "yyyy-MM-dd")) ||
        "";
      this.listQuery.end =
        (this.listQuery.date &&
          this.listQuery.date[1] &&
          g.format(this.listQuery.date[1], "yyyy-MM-dd")) ||
        "";
      getlist(this.listQuery).then((response) => {
        this.list = response.data;
        this.total = response.count || 0;
        setTimeout(() => {
          this.listLoading = false;
        }, 500);
      });
    },
    handleFilter() {
      this.getList();
    },
    sortHanlde(column) {
      console.log(column);
      this.listQuery.filed = column.prop;
      this.listQuery.sort = column.order;
      this.getList();
    },
    pageHandle(page) {
      this.listQuery.page = page.page;
      this.listQuery.limit = page.limit;
      this.getList();
    },
    showLog(row) {
      this.logShow.show = true;
      this.logShow.data = row;
    },
    downModle() {
      this.$confirm(`导出该数据需要大量时间或者先选好条件再导出, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.listLoading = true;
          getlist4down(this.listQuery).then((response) => {
            var data = response.data;
            this.handleDownload(data);
            this.listLoading = false;
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消导出",
          });
        });
    },
    handleDownload(data) {
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then((excel) => {
        const tHeader = [
          "序号",
          "游戏名",
          "游戏端口",
          "充值人员",
          "充值账号",
          "付钱账号",
          "可充值金额",
          "金兰ID",
          "金兰名字",
          "金额",
          "区服",
          "充值时间",
        ];
        const filterVal = [
          "ID",
          "Game",
          "Chan",
          "Role_Name",
          "Account",
          "RechargeAccount",
          "Residue",
          "OtherSideID",
          "OtherSideName",
          "Money",
          "Server",
          "Create_Time",
        ];
        data = this.formatJson(filterVal, data);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "充值订单",
          autoWidth: true,
          bookType: "xls",
        });
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map((v) =>
        filterVal.map((j) => {
          return v[j];
        })
      );
    },
  },
};
</script>

